package ${package}.endpoint;

import java.io.IOException;
import java.io.InputStream;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import java.util.jar.Manifest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("info")
public class Info {
	
	@GetMapping
	public ServerInfomationVO get() throws IOException {
		ServerInfomationVO info = new ServerInfomationVO();
		try (InputStream mfis = getClass().getResourceAsStream("/META-INF/MANIFEST.MF")) {
			Manifest mf = new Manifest(mfis);
			Attributes attrs = mf.getMainAttributes();
			info.setVendor(attrs.getValue(Name.IMPLEMENTATION_VENDOR));
			info.setTitle(attrs.getValue(Name.IMPLEMENTATION_TITLE));
			info.setBuild(attrs.getValue("Implementation-Build"));
			info.setVer(attrs.getValue(Name.IMPLEMENTATION_VERSION));
		}
		return info;
	}
	
	public class ServerInfomationVO {
		
		String vendor;
		String title;
		String ver;
		String build;
		
		public String getVendor() {
			return vendor;
		}

		public void setVendor(String vendor) {
			this.vendor = vendor;
		}

		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}
		
		public String getVer() {
			return ver;
		}

		public void setVer(String ver) {
			this.ver = ver;
		}

		public String getBuild() {
			return build;
		}

		public void setBuild(String build) {
			this.build = build;
		}
		
	}

}
